package com.yyfax.ph.personal.subaccount;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.aspsine.irecyclerview.IViewHolder;
import com.yyfax.common.recyclerview.BaseRecycleAdapter;
import com.yyfax.ph.R;
import com.yyfax.ph.base.YJPH;

import java.util.List;


/**
 * 子账号管理的adapter
 * Created by zhangxian on 2017/11/3.<br>
 * Copyright 2017 www.yylending.com. All Rights Reserved.<br><br>
 */
public class SubAccountAdapter extends BaseRecycleAdapter<SubAccountModel.SubAccountBean> {

	public interface SubAccountDetailItemClickListener {
		void onDetailItemClick(SubAccountModel.SubAccountBean bean);
	}

	private SubAccountDetailItemClickListener mListener;

	public void setListener(SubAccountDetailItemClickListener listener) {
		mListener = listener;
	}

	public SubAccountAdapter() {
		super();
	}

	public SubAccountAdapter(List<SubAccountModel.SubAccountBean> data) {
		super(data);
	}

	@Override
	public IViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.sub_account_item_layout, null);
		return new SubAccountAdapter.ViewHolder(view);
	}

	@Override
	public void onBindViewHolder(IViewHolder holder, int position) {
		SubAccountAdapter.ViewHolder view = (SubAccountAdapter.ViewHolder) holder;
		final SubAccountModel.SubAccountBean bean = getDataSet().get(position);
		if (TextUtils.isEmpty(bean.name) || bean.applyCount == 0) {
			/**
			 * 未认证
			 */
			if (TextUtils.isEmpty(bean.name)) {
				view.mNameTv.setText(YJPH.getInstance().getString(R.string.not_virified));
			}else{
				view.mNameTv.setText(bean.name);
			}
			view.mNameTv.setTextColor(YJPH.getInstance().color(R.color.color_999999));
			view.mphoneTv.setTextColor(YJPH.getInstance().color(R.color.color_999999));
			view.mApplyCountTv.setTextColor(YJPH.getInstance().color(R.color.color_999999));
			view.mApplyCountTv.setCompoundDrawables(null, null, null, null);
			view.mItemRl.setOnClickListener(null);
		} else {
			/**
			 * 已经认证
			 */
			view.mNameTv.setText(bean.name);
			view.mNameTv.setTextColor(YJPH.getInstance().color(R.color.color_333333));
			view.mphoneTv.setTextColor(YJPH.getInstance().color(R.color.color_666666));
			view.mApplyCountTv.setTextColor(YJPH.getInstance().color(R.color.color_666666));
			Drawable drawable = YJPH.getInstance().getResources().getDrawable(R.drawable.right_arrow_icon);
			drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
			view.mApplyCountTv.setCompoundDrawables(null, null, drawable, null);
			view.mItemRl.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View view) {
					mListener.onDetailItemClick(bean);
				}
			});
		}

		view.mphoneTv.setText(String.valueOf(bean.phone));
		view.mApplyCountTv.setText(String.valueOf(bean.applyCount));
	}

	@Override
	public int getItemCount() {
		return getCount();
	}

	class ViewHolder extends IViewHolder {
		@BindView(R.id.item_rl)
		RelativeLayout mItemRl;
		@BindView(R.id.name_tv)
		TextView mNameTv;
		@BindView(R.id.phone_tv)
		TextView mphoneTv;
		@BindView(R.id.apply_count_tv)
		TextView mApplyCountTv;

		ViewHolder(View view) {
			super(view);
			ButterKnife.bind(this, view);
		}
	}
}
